
package com.lanou.dllo.soccernews.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.dllo.soccernews.R;
import com.lanou.dllo.soccernews.bean.HelpAttackBean;
import com.lanou.dllo.soccernews.bean.RankingsEntity;
import com.lanou.dllo.soccernews.bean.ShooterBean;
import com.lanou.dllo.soccernews.volley.GetVolleyDatasUtil;

import java.util.List;

/**
 * Created by dllo on 15/11/4.
 */
public class HelpAttackAtapter extends BaseAdapter {

    List<HelpAttackBean> helpAttackBeans;

    private LayoutInflater mInflater;
    private Context context;

    public HelpAttackAtapter(Context context) {
        mInflater = LayoutInflater.from(context);

        this.context = context;
    }

    public void addDatas(List<HelpAttackBean> helpAttackBeans) {
//        if (this.rankingsEntities == null) {
//            this.rankingsEntities = new ArrayList<>();
//        }
//        this.rankingsEntities.clear();
        //      this.rankingsEntities.addAll(rankingsEntities);
        this.helpAttackBeans = helpAttackBeans;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return helpAttackBeans != null && helpAttackBeans.size() > 0 ? helpAttackBeans.size()
                : 0;
    }

    @Override
    public Object getItem(int position) {
        return helpAttackBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ShootViewHodle hodle;
        if (convertView == null) {
            hodle = new ShootViewHodle();
            convertView = mInflater.inflate(R.layout.item_helpattack, parent, false);

            hodle.name = (TextView) convertView.findViewById(R.id.at_name);
            hodle.team_name = (TextView) convertView.findViewById(R.id.at_teamname);
            hodle.count = (TextView) convertView.findViewById(R.id.at_count);
            hodle.shoot_position = (TextView) convertView.findViewById(R.id.at_position);

            hodle.log = (ImageView) convertView.findViewById(R.id.at_log);
            convertView.setTag(hodle);
        } else {
            hodle = (ShootViewHodle) convertView.getTag();
        }
        HelpAttackBean helpAttackBean = helpAttackBeans.get(position);

        if (helpAttackBean != null) {
            // Log.i("lanou", rankingsEntity.getRank() + "****");
            hodle.name.setText(helpAttackBean.getName());
            hodle.team_name.setText(helpAttackBean.getTeam_name());
            hodle.count.setText(helpAttackBean.getCount());
            hodle.shoot_position.setText(position + 1 + "");


            String teamId = helpAttackBean.getTeam_id();

            String logUrl = "http://img.dongqiudi.com/data/pic/" + teamId + ".png";


            GetVolleyDatasUtil.getNetWorkImg(logUrl, hodle.log);

        }

        return convertView;
    }

    class ShootViewHodle {
        TextView name, team_name, count, shoot_position;
        ImageView log;
    }
}


